package com.xintonghua.bussiness.ui;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.xintonghua.base.ui.ImageActivity;
import com.xintonghua.base.widget.MyItemTextView;
import com.xintonghua.bussiness.BuildConfig;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.api.HttpCent;
import com.xintonghua.bussiness.api.manager.AuthManager;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.Contant;
import com.xintonghua.bussiness.bean.UserInfoBean;
import com.xintonghua.bussiness.ui.fragment.client.ArchivesActivity;
import com.xintonghua.bussiness.ui.fragment.client.CustomersActivity;
import com.xintonghua.bussiness.ui.fragment.client.XiaoFeiActivity;
import com.xintonghua.bussiness.ui.fragment.client.user.ClubCardActivity;
import com.xintonghua.bussiness.ui.fragment.client.user.ConsumeActivity;
import com.xintonghua.bussiness.ui.fragment.client.user.HairdressingTestActivity;
import com.xintonghua.bussiness.ui.fragment.client.user.ProductActivity;
import com.xintonghua.bussiness.util.GlideUtils;
import com.xintonghua.bussiness.util.JsonUtil;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MyState;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：wanxianyi
 * 时间：2018/1/13.
 * 包名：com.xintonghua.bussiness.ui
 * <p>
 * 数据完善liqi
 * 包名：com.xintonghua.bussiness.ui
 */

public class CustomerActivity extends BaseActivity implements initCustomerData {
    @BindView(R.id.utils_record)
    MyItemTextView utilsRecord;
    @BindView(R.id.utils_club_card)
    MyItemTextView utilsClubCard;
    @BindView(R.id.utils_product_items)
    MyItemTextView utilsProductItems;
    @BindView(R.id.utils_consume)
    MyItemTextView utilsConsume;
    @BindView(R.id.utils_test)
    MyItemTextView utilsTest;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_return)
    TextView tvReturn;
    protected ImmersionBar mImmersionBar;
    @BindView(R.id.iv_head)
    ImageView ivHead;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.iv_bi)
    ImageView ivBi;
    @BindView(R.id.ll_user)
    LinearLayout llUser;
    @BindView(R.id.rl_red)
    RelativeLayout rlRed;
    @BindView(R.id.tv_yuE)
    TextView tvYuE;
    @BindView(R.id.tv_all_score)
    TextView tvAllScore;
    @BindView(R.id.tv_member_level)
    TextView tvMemberLevel;
    @BindView(R.id.tv_xiaofei)
    TextView tvXiaofei;
    @BindView(R.id.tv_enter_time)
    TextView tvEnterTime;
    @BindView(R.id.utils_excharge)
    MyItemTextView utilsExcharge;

    Contant contantbean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer);
        ButterKnife.bind(this);
        contantbean = (Contant) JumpUtils.getSerializable(this);
        initImmersionBar();
        getNetDataList();
    }


    @OnClick({R.id.iv_back, R.id.utils_record, R.id.utils_club_card, R.id.utils_product_items, R.id.utils_consume, R.id.utils_test, R.id.tv_return, R.id.tv_xiaofei, R.id.ll_user, R.id.utils_excharge})
    public void onViewClicked(View view) {
        Bundle bundle;
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.utils_record:
//                bundle = new Bundle();
//                bundle.putInt(BuildConfig.FLAVOR, R.mipmap.shop_dangan);
//                openActivity(ImageActivity.class, bundle);
                JumpUtils.jumpto(CustomerActivity.this, ArchivesActivity.class, (Serializable) contantbean);
                break;
            case R.id.utils_club_card:

                Bundle bun = new Bundle();
                bun.putSerializable("data0", (Serializable) contantbean);
                bun.putSerializable("data1", (Serializable) userInfoBean);

                JumpUtils.jumptoB(CustomerActivity.this, ClubCardActivity.class, bun);
                break;
            case R.id.utils_product_items:
                Bundle bun1 = new Bundle();
                bun1.putSerializable("data0", (Serializable) contantbean);
                bun1.putSerializable("data1", (Serializable) userInfoBean);
                JumpUtils.jumptoB(CustomerActivity.this, ProductActivity.class, bun1);
                break;
            case R.id.utils_consume:

                Bundle bun2 = new Bundle();
                bun2.putSerializable("data0", (Serializable) contantbean);
                bun2.putSerializable("data1", (Serializable) userInfoBean);
                JumpUtils.jumptoB(CustomerActivity.this, ConsumeActivity.class, bun2);
                break;
            case R.id.utils_test:
//                openActivity(HairdressingTestActivity.class);
                Bundle bun3 = new Bundle();
                bun3.putSerializable("data0", (Serializable) contantbean);
                bun3.putSerializable("data1", (Serializable) userInfoBean);
                JumpUtils.jumptoB(CustomerActivity.this, HairdressingTestActivity.class, bun3);
                break;
            case R.id.tv_return:
//                bundle = new Bundle();
//                bundle.putInt(BuildConfig.FLAVOR, R.mipmap.shop_return);
//                openActivity(ImageActivity.class, bundle);
                JumpUtils.jumpto(CustomerActivity.this, CustomersActivity.class, contantbean);
                break;
            case R.id.tv_xiaofei://消费
                JumpUtils.jumpto(CustomerActivity.this, XiaoFeiActivity.class, contantbean);
                break;
            case R.id.ll_user: //查看用户信息
                bundle = new Bundle();
                bundle.putParcelable(BuildConfig.FLAVOR, userInfoBean);
                openActivity(ModifyMemberActivity.class, bundle);
                break;
            case R.id.utils_excharge:
                if (!AuthManager.geteAuth().isIsBoss()) {
                    mToast("该功能只限店长使用");
                    return;
                }
                bundle = new Bundle();
                bundle.putString(BuildConfig.FLAVOR, contantbean.getId() + "");
                openActivity(ExchargeActivity.class, bundle);
                break;
        }
    }

    /**
     * 初始化沉浸式
     */
    protected void initImmersionBar() {
        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.keyboardEnable(true).navigationBarWithKitkatEnable(false).init();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        mImmersionBar.destroy();
    }

    @Override
    public void getNetDataList() {
        HttpCent.getInstance(this).detail("" + contantbean.getId(), this, MyState.requestOne);
    }

    UserInfoBean userInfoBean;

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        switch (order) {
            case MyState.requestOne:
                try {
                    userInfoBean = JsonUtil.getEntityByJsonString(data.toString(), UserInfoBean.class);

                    initView(userInfoBean);


                } catch (Exception e) {
                    e.printStackTrace();
                }


                break;
        }
    }

    private void initView(UserInfoBean userInfoBean) {

        GlideUtils.loadCricle(this, ivHead, userInfoBean.getHead_img());
        tvUserName.setText("" + userInfoBean.getNickname());
        tvPhone.setText("" + userInfoBean.getPhone());
        tvYuE.setText("" + userInfoBean.getMoney());

        tvEnterTime.setText("加入时间:" + userInfoBean.getVip_time());
        tvAllScore.setText("" + userInfoBean.getTotalScore());

        tvMemberLevel.setText("" + userInfoBean.getLv() + "级");
    }


}

interface initCustomerData {
    void getNetDataList();
}
